<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增采购计划商品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-purchaseitem-add">
            <input name="purchasingUnitId" class="form-control" type="hidden" th:value="${purchasingUnitId}">
            <input name="purchasePlanId" class="form-control" type="hidden" th:value="${purchasePlanId}">

            <div class="form-group">    
                <label class="col-sm-3 control-label">商品种类：</label>
                <div class="col-sm-8">

                    <select id="goodsClassificationId" name="goodsClassificationId" class="form-control" th:onchange="'javascript:selectGoodsType();'" >
                        <option th:each="sysGoodsclassification:${sysGoodsclassificationList}" th:value="${sysGoodsclassification.goodsClassificationId}" th:text="${sysGoodsclassification.goodsClassificationName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">

                <label class="col-sm-3 control-label">货物名称：</label>

                <div th:fragment="goods_refresh" th:id="id_goods_refresh">

                <div class="col-sm-8">
                    <span id="caigouGoods">
                    <!--<select id="goodsId" name="goodsId" class="form-control">
                        <option >请选择</option>
                    </select>-->
                        <select id="goodsId" name="goodsId" class="form-control">
                        <option th:each="good:${goods}" th:value="${good.goodsId}" th:text="${good.goodsName}">
                            --请选择货物名称--
                        </option>
                    </select>
                    </span>
                </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/purchaseitem"
        $("#form-purchaseitem-add").validate({
            focusCleanup: true
        });
         function selectGoodsType(){
            var goodsClassificationId = $("#goodsClassificationId option:selected").val();

            $.ajax({
                type: "POST",

                url:prefix+"/selectShangPi",

                data: {goodsClassificationId:goodsClassificationId},
                success: function(data1){

                    $("#caigouGoods").html(data1);
                }

            });

        }
/*        function selectGoodsType2(){
            var goodsClassificationId = $("#goodsClassificationId option:selected").val();
            alert(goodsClassificationId);
            $.ajax({

                type: "POST",
                url: "../selectShangPi",
                data: {goodsClassificationId:goodsClassificationId},
                dataType: "json",
                success: function (data){
                    var str = '<option>--请选择货物名称--</option>';
                    if(data.length > 0){
                        for(var i in data){
                            str+='<option value="'+data[i].goodsId+'">'+data[i].goodsName+'</option>';
                        }
                    }
                    $("#caigouGoods").html(str);
                }
            });
        }*/
       /* $("#goodsClassificationId").bind("change",function () {
            alert("444");
            var id = $("#goodsClassificationId option:selected").val();
            var url = prefix +"/selectShangPi"+ id;

        });*/
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-purchaseitem-add').serialize());
            }
        }


    </script>
</body>
</html>